// CSE 142 Winter 2008, Marty Stepp // This file describes a new type of objects named Point. // public class Point { // fields (data inside each Point object) int x; // each Point object has two ints inside it: int y; // x and y. // methods (behavior inside each Point object) // Adjusts this Point object's location by the given amounts. public void translate(int dx, int dy) { // This code runs inside a particular Point object. // (We say the code runs "in the context of" that object.) // The code knows which object that is, // and it knows how to access or change that object's fields. x = x + dx; // change "this" Point's x y = y + dy; // change "this" Point's y } // Returns the distance between this Point and the origin, (0, 0). public double distanceFromOrigin() { // a^2 + b^2 = c^2 double distance = Math.sqrt(x * x + y * y); return distance; } }